#include <QtGui/QApplication>
#include <QTimer>
#include <QTime>
#include <QGraphicsScene>
#include <QGraphicsView>
#include "mainwindow.h"
#include <math.h>

#include "movingobject.h"

int main(int argc, char *argv[])
{
    //application setup
    QApplication app(argc, argv);
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

    //GET AND SET SCENE DIMENSIONS
    float windowWidth = 1440.0;
    float windowHeight = 800.0;

#if defined(Q_OS_LINUX)
    windowWidth = 1360.0*2.0;
    windowHeight = 768.0*2.0;
#endif
#if defined(Q_WS_WIN)
    windowWidth = 1280.0;
    windowHeight = 750.0;
#endif

    //setup the scene
    QGraphicsScene scene;
    scene.setSceneRect(-windowWidth/2.0, -windowHeight/2.0, windowWidth, windowHeight);//-700, -350, 1400, 700);
    scene.setItemIndexMethod(QGraphicsScene::NoIndex);//QGraphicsScene::BspTreeIndex);//

    //scene.addItem( &sageVis );

    QTimer timer;
    for(int i = 0; i < 100; i++)
    {
        MovingObject* m = new MovingObject();
        m->setPos(rand()% (int)windowWidth -windowWidth/2.0 , rand( ) % (int)windowHeight-windowHeight/2.0 );
        scene.addItem( m );
        //m->target( 0 , m->pos().y() );
        m->target( rand()% (int)windowWidth -windowWidth/2.0 , rand( ) % (int)windowHeight-windowHeight/2.0 );
        QObject::connect(&timer, SIGNAL(timeout()), m, SLOT(advance()));
    }
    timer.start(1000 / 33);

    QGraphicsView view(&scene);
    view.setRenderHint(QPainter::Antialiasing);
    view.setBackgroundBrush(QBrush(Qt::black));

    view.setCacheMode(QGraphicsView::CacheBackground);
    view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    view.setDragMode(QGraphicsView::ScrollHandDrag);

    view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "BioSAGE"));
    view.resize(windowWidth,windowHeight);
    view.show();

    return app.exec();
}
